package com.huawei.hianalytics.ab.bc.bc;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.provider.Settings.Secure;
import android.text.TextUtils;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.lang.reflect.InvocationTargetException;

public abstract class ab {

    static class ab extends Exception {
        ab(String str) {
            super(str);
        }
    }

    private static Object ab(Class cls, String str, Class[] clsArr, Object[] objArr) {
        Object obj = null;
        if (cls == null) {
            throw new ab("class is null in invokeStaticFun");
        }
        if (clsArr == null) {
            if (objArr != null) {
                throw new ab("paramsType is null, but params is not null");
            }
        } else if (objArr == null) {
            throw new ab("paramsType or params should be same");
        } else if (clsArr.length != objArr.length) {
            throw new ab("paramsType len:" + clsArr.length + " should equal params.len:" + objArr.length);
        }
        try {
            try {
                obj = cls.getMethod(str, clsArr).invoke(null, objArr);
            } catch (IllegalAccessException e) {
                com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "invokeStaticFun(): method invoke Exception!");
            } catch (IllegalArgumentException e2) {
                com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "invokeStaticFun(): Illegal Argument!");
            } catch (InvocationTargetException e3) {
                com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "invokeStaticFun(): Invocation Target Exception!");
            }
        } catch (NoSuchMethodException e4) {
            com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "invokeStaticFun(): cls.getMethod(),No Such Method !");
        }
        return obj;
    }

    private static Object ab(String str, String str2, Class[] clsArr, Object[] objArr) {
        try {
            return ab(Class.forName(str), str2, clsArr, objArr);
        } catch (ClassNotFoundException e) {
            com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "invokeStaticFun() Not found class!");
            return null;
        } catch (ab e2) {
            com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "invokeStaticFun(): Static function call Exception ");
            return null;
        }
    }

    public static String ab() {
        return ab("ro.build.version.emui", "");
    }

    public static String ab(Context context) {
        return context == null ? "" : context.getPackageName();
    }

    public static String ab(String str, String str2) {
        if (TextUtils.isEmpty(str)) {
            return str2;
        }
        CharSequence ab = ab("android.os.SystemProperties", str, str2);
        if (TextUtils.isEmpty(ab)) {
            ab = ab("com.huawei.android.os.SystemPropertiesEx", str, str2);
        }
        return ab;
    }

    private static String ab(String str, String str2, String str3) {
        Object ab = ab(str, "get", new Class[]{String.class, String.class}, new Object[]{str2, str3});
        return ab != null ? (String) ab : str3;
    }

    public static String bc(Context context) {
        String str = "";
        if (context != null) {
            try {
                str = context.getPackageManager().getPackageInfo(ab(context), 0).versionName;
            } catch (NameNotFoundException e) {
                com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "getVersion(): The package name is not correct!");
            }
        }
        return str;
    }

    @SuppressLint({"HardwareIds"})
    public static String cd(Context context) {
        return context == null ? "" : Secure.getString(context.getContentResolver(), "android_id");
    }

    public static String de(Context context) {
        String str = "Unknown";
        try {
            ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), DnsConfig.MAX_CACHE_ENTRIES);
            if (!(applicationInfo == null || applicationInfo.metaData == null)) {
                Object obj = applicationInfo.metaData.get("CHANNEL");
                if (obj != null) {
                    String obj2 = obj.toString();
                    return obj2.length() > 256 ? "Unknown" : obj2;
                }
            }
        } catch (NameNotFoundException e) {
            com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "getChannel(): The packageName is not correct!");
        }
        return str;
    }
}
